<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/css/plugins/layui/css/layui.css}">
</head>
<body>
<div>
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="name" name="name" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="pass" name="pass" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出生日期</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="birthday" name="birthday" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属部门</label>
            <div class="layui-input-inline layui-input-wrap">
                <select name="deptId" id="deptId" th:with="depts=${@deptService.getDeptList()}">
                    <option>请选择 </option>
                    <option th:each="dept : ${depts}" th:text="${dept.deptName}" th:value="${dept.deptId}"></option>
                </select>
            </div>
        </div>
<!--        <div class="layui-form-item">-->
<!--            <input type="hidden" name="roleIds" id="roleIds" value="">-->
<!--            <label class="layui-form-label">角色</label>-->
<!--            <div class="layui-input-block" th:with="roles=${@roleService.list()}">-->
<!--                <input name="roleId" lay-filter="role-filter" type="checkbox" th:each="role : ${roles}" th:title="${role.roleName}" th:value="${role.roleId}" lay-skin="primary">-->
<!--            </div>-->
<!--        </div>-->
        <div class="layui-form-item">
            <input type="hidden" name="roleIds" id="roleIds" value="">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block" th:with="roles=${@roleService.list()}">
                <input name="roleId" lay-filter="role-filter" type="checkbox" th:each="role:${roles}" th:title="${role.roleName}" th:value="${role.roleId}" lay-skin="primary">
            </div>
        </div>
    </div>

</div>


<script th:src="@{/js/plugins/layui/layui.js}"></script>
<script th:src="@{/js/jquery.min.js}"></script>

<script>
    // 异步请求加载部门列表
        layui.use(function (){
        var laydate = layui.laydate;
        var form=layui.form;
        var $=layui.$;
        var layer = layui.layer;
        laydate.render({
            elem: '#birthday',
            type: 'date'
        });

       // form.on('checkbox(role-filter)',function(data){
       //     //获取所有选中的checkbox
       //     var checkeds="";
       //     $("input[name=roleId]:checked").each(function (i){
       //         if(i==0){
       //             checkeds+=$(this).val;
       //         }else{
       //             checkeds+=","+$(this).val;
       //         }
       //     })
       //     $("#roleIds").val(checkeds);
       // })
            form.on('checkbox(role-filter)', function (data){
                // 获取所有选中的checkbox   1,3   2,4   1,2,3,4
                var checkeds = "";
                $("input[name=roleId]:checked").each(function (i){
                    if (i == 0) {
                        checkeds += $(this).val();
                    } else {
                        checkeds += "," + $(this).val();//val一定要加()
                    }
                })
                $("#roleIds").val(checkeds);
            })



        })
</script>
</body>
</html>
